﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="SequenceArrayItemMin0", Namespace="http://kis.x-road.eu/", Target=typeof(SequenceArrayItemMin0))]
    public class SequenceArrayItemMin0Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected SequenceArrayItemMin0 clazz;
        
        public SequenceArrayItemMin0Serializer(SequenceArrayItemMin0 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("NonNil_Min1_Max1");
            if (clazz.NonNilMin1Max1!=null) {
                for (int x = 0; ((clazz.NonNilMin1Max1 != null) 
                            && (x < clazz.NonNilMin1Max1.Count)); x = (x + 1)) {
                    if (clazz.NonNilMin1Max1[x]!=null) {
                        Writer.WriteStartElement("itemNonNil");
                        Writer.WriteString(clazz.NonNilMin1Max1[x].ToString());
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : NonNilMin1Max1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Nil_Min1_Max1");
            if (clazz.NilMin1Max1!=null) {
                for (int x = 0; ((clazz.NilMin1Max1 != null) 
                            && (x < clazz.NilMin1Max1.Count)); x = (x + 1)) {
                    if (clazz.NilMin1Max1[x]!=null) {
                        Writer.WriteStartElement("itemNonNil");
                        Writer.WriteString(clazz.NilMin1Max1[x].ToString());
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            if (clazz.NonNilMin0Max1!=null) {
                Writer.WriteStartElement("NonNil_Min0_Max1");
                for (int x = 0; ((clazz.NonNilMin0Max1 != null) 
                            && (x < clazz.NonNilMin0Max1.Count)); x = (x + 1)) {
                    if (clazz.NonNilMin0Max1[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaNonNilMin0Max1 = this.GetMetaData(clazz.NonNilMin0Max1[x]);
                        if (ShouldWriteTypeAttribute(typeof(global::Kis.Xroad.Eu.Employee), clazz.NonNilMin0Max1[x].GetType())) {
                            Writer.WriteTypeAttribute(metaNonNilMin0Max1.TypeQualifiedName.Namespace, metaNonNilMin0Max1.TypeQualifiedName.Name);
                        }
                        var nonNilMin0Max1Serializer = metaNonNilMin0Max1.NewSerializer(clazz.NonNilMin0Max1[x]);
                        nonNilMin0Max1Serializer.WriteXmlAttributes(Writer);
                        nonNilMin0Max1Serializer.WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.NilMin0Max1!=null) {
                Writer.WriteStartElement("Nil_Min0_Max1");
                for (int x = 0; ((clazz.NilMin0Max1 != null) 
                            && (x < clazz.NilMin0Max1.Count)); x = (x + 1)) {
                    if (clazz.NilMin0Max1[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.NilMin0Max1[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="NonNil_Min1_Max1") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SequenceArrayItemMin0>NonNil_Min1_Max1");
                }
                clazz.NonNilMin1Max1 = new System.Collections.Generic.List<global::Kis.Xroad.Eu.WorkDay>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("NonNil_Min1_Max1");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "itemNonNil")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>SequenceArrayItemMin0>NonNil_Min1_Max1>itemNonNil");
                        }
                        clazz.NonNilMin1Max1.Add(new global::Kis.Xroad.Eu.WorkDay(Reader.ReadElementString("itemNonNil")));
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceArrayItemMin0>NonNil_Min1_Max1", Reader.LocalName);
            }
            if (Reader.LocalName=="Nil_Min1_Max1") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.NilMin1Max1 = new System.Collections.Generic.List<SequenceArrayItemMin0.NilMin1Max1Type>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Nil_Min1_Max1");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "itemNonNil")); ) {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>SequenceArrayItemMin0>Nil_Min1_Max1>itemNonNil");
                            }
                            clazz.NilMin1Max1.Add(new SequenceArrayItemMin0.NilMin1Max1Type(Reader.ReadElementString("itemNonNil")));
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceArrayItemMin0>Nil_Min1_Max1", Reader.LocalName);
            }
            if (Reader.LocalName=="NonNil_Min0_Max1") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SequenceArrayItemMin0>NonNil_Min0_Max1");
                }
                clazz.NonNilMin0Max1 = new System.Collections.Generic.List<global::Kis.Xroad.Eu.Employee>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("NonNil_Min0_Max1");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>SequenceArrayItemMin0>NonNil_Min0_Max1>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaNonNilMin0Max1 = this.GetMetaData<global::Kis.Xroad.Eu.Employee>(Reader, "Employee", "http://kis.x-road.eu/");
                        global::Kis.Xroad.Eu.Employee item = metaNonNilMin0Max1.NewEntity<global::Kis.Xroad.Eu.Employee>();
                        clazz.NonNilMin0Max1.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            var nonNilMin0Max1Serializer = metaNonNilMin0Max1.NewSerializer(item);
                            nonNilMin0Max1Serializer.ReadXmlAttributes(Reader);
                            Reader.ReadStartElement("item");
                            nonNilMin0Max1Serializer.ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Nil_Min0_Max1") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.NilMin0Max1 = new System.Collections.Generic.List<System.Decimal?>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Nil_Min0_Max1");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                clazz.NilMin0Max1.Add(new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("item")).Value);
                            }
                            else {
                                clazz.NilMin0Max1.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
